package com.cashmama.market.api.domain.service.actions;

import com.cashmama.market.api.domain.enums.UserProfileActionEnum;
import com.cashmama.market.api.domain.enums.UserProfileActionStatusEnum;
import com.cashmama.market.api.infras.enums.ActionTypeEnums;
import com.cashmama.market.api.infras.enums.JumpRouterEnum;
import com.qianli.cashmama.product.facade.result.AppConfig;
import com.qianli.user.enums.UserAuthStatusEnum;
import com.qianli.user.ro.auth.UserAuthStatusRO;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * User: yujianfu (mr.vencnet@gmail.com)
 * Date: 2019-12-24
 * Time: 14:46
 */
@Service
public class WorkAction extends BaseAction {

    @PostConstruct
    public void init() {
        ActionListService.actionListHandler.put(ActionTypeEnums.WORK, this);
    }

    @Override
    public ActionDetailVo getAction(String userCode, AppConfig appConfig, UserAuthStatusRO userAuthStatus) {

        ActionDetailVo actionDetailVo = new ActionDetailVo()
                .setIconUrl(appConfig.getEmploymentInfoLightIconUrl())
                .setTitle(UserProfileActionEnum.EMPLOYMENT_INFORMATION.getTitle())
                .setStatus(0)
                .setEnableToClick(true)
                .setJumpUrl(JumpRouterEnum.PERSONAL_INFO_EMPLOYEE.getJumpUrl())
                .setStatusText(UserProfileActionStatusEnum.NOT_AUTHORIZED.getDesc());

        boolean employmentInformationComplete = Objects.equals(userAuthStatus.getBaseWorkStatus(), UserAuthStatusEnum.SUCCESS.getCode());
        if (employmentInformationComplete) {
            actionDetailVo.setStatus(1).setEnableToClick(false)
                .setStatusText(UserProfileActionStatusEnum.AUTHORIZED.getDesc());
        }

        return actionDetailVo;
    }

}
